<?php
namespace Home\Controller;
use Think\Controller;
class UserController extends Controller{
    public function reg(){
        if($_POST){
            $user = D('user');
            //print_r($user);
            //print_r(I('ewm'));

            $verify = I('ewm');
            //var_dump(check_verify($verify));
            if(!check_verify($verify)){
                 $this->error("验证码错误！");
             }

            if (!$user->create()){
                // 如果创建失败 表示验证没有通过 输出错误提示信息
                //exit($user->getError());
                $this->error($user->getError());
            }//else if(!check_verify(I('ewm'))){
                //$this->error("亲，验证码输错了哦！");
            //}
            else{
                $user->create();
                $user->add();
            }
        }
        $this->display();
    }

    public function ceshi(){
        //print_r(I('ewm'));
        if($_POST){
            $code = I('ewm');
            echo $code;
            $verify = new \Think\Verify();
            var_dump($verify->check($code));
            var_dump($_SESSION['verify']);
        }
        $this->display();
    }

    public function yzm(){
        $Verify = new \Think\Verify();
        $Verify->fontSize = 18;
        $Verify->length   = 4;
        $Verify->useNoise = false;
        $Verify->codeSet = '0123456789';
        $Verify->imageW = 130;
        $Verify->imageH = 50;
        $Verify->entry();
    }

    public function login(){
        if(!empty($_POST)){
            //$verify = I('ewm');
            //if(!check_verify($verify)){
            //     $this->error("验证码错误！");
             //}
             //$userMode ='';
             $userModel = D('user');
             $userdata['user_name'] = I('user_name');
             $userdata['user_passwd'] = I('user_passwd');
             //print_r($userdata);
             $a = $userModel->where($userdata)->find();
             //var_dump($a);
             if(!$a){
                 $this->error('用户名或密码错误,请重新输入');
             }else{

             }
        }
        $this->display();
    }

}
?>
